package com.zzz.gp.service;

import com.alibaba.fastjson.JSONObject;
import com.zzz.gp.bean.LogRecord;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.logging.Logger;

/**
 * @description:
 * @author: ZeckZheng
 * @time: 2023/10/31 5:31
 */
@Service
public class LogSave {
    Logger logger = Logger.getLogger("BusinessLog");

    @Async("myAsync")
    public void save(LogRecord logRecord) {
        DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        LocalDateTime localDateTime=LocalDateTime.now();

        Map<String, String> map = new HashMap<>();
        Random random=new Random();
        String s= String.valueOf(random.nextInt(1000));

        map.put("uname", s+"T");
        map.put("app_id", s+"xxdxd");
        map.put("biz_type", s+"0x10");
        map.put("stat_time", localDateTime.format(dtf));
        String log = JSONObject.toJSONString(map);
        logger.info(log);
    }
    //@Scheduled(cron = "0/2 * * * * *")
    public void test(){

        for (int i = 0; i < 2000; i++) {
            save(null);
        }
    }
}
